package com.skwyb.form.service.admin;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.skwyb.form.bean.common.PageData;
import com.skwyb.form.bean.dto.SysMenu;
import com.skwyb.form.bean.req.admin.GetMenuListReq;
import com.skwyb.form.mapper.SysMenuMapper;
import com.skwyb.form.utils.PageUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Log4j2
@Service
public class SysMenuService extends ServiceImpl<SysMenuMapper, SysMenu> {
    @Autowired
    private SysMenuMapper menuMapper;

    /**
     * 查询menu
     *
     * @param req menu
     * @return list
     */
    public List<SysMenu> selectMenuList(GetMenuListReq req) {
        req.setStartIndex(PageUtil.getStartIndex(req.getPage(), req.getRows()));
        return menuMapper.selectByMenu(req);
    }

    /**
     * 查询menu
     *
     * @param req menu
     * @return PageData
     */
    public PageData<SysMenu> selectMenuByPage(GetMenuListReq req) {
        PageData<SysMenu> pageData = new PageData<>();
        pageData.setData(selectMenuList(req));
        pageData.setTotal(menuMapper.selectCountByMenu(req));
        return pageData;
    }
}
